package com.vincent.sciinfo.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.vincent.sciinfo.pojo.Patent;
import com.vincent.sciinfo.pojo.TSMResult;
import com.vincent.sciinfo.service.PatentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/patent")
public class PatentController {

    @Autowired
    private PatentService patentServer;

    @RequestMapping("/show_patent")
    public PageInfo showPatent(@RequestParam String Id, @RequestParam int ope, @RequestParam(value = "pn", defaultValue = "1") int pn) {
        PageHelper.startPage(pn, 5);
        List<Patent> list = patentServer.selectPatent(ope, Id);
        PageInfo pageInfo = new PageInfo(list, 5);
        return pageInfo;
    }

    @RequestMapping("/selCheckAndRemovePatent")
    public PageInfo selCheckAndRemovePatent(@RequestParam Integer pn, @RequestParam Integer pageSize){
        PageHelper.startPage(pn, pageSize);
        List<Patent> patents = patentServer.selectCheckAndRemovePatent();
        PageInfo pageInfo = new PageInfo(patents, pageSize);
        return pageInfo;
    }

    @RequestMapping("/add_patent")
    public int insertPatent(@RequestBody(required = false) Patent patent){
        return patentServer.insertPatent(patent);
    }

    @RequestMapping("/updatePatentStatus")
    public void updatePatentStatus(@RequestParam String patentId, @RequestParam int operaCode){
        patentServer.updatePatentStatus(patentId, operaCode);
    }

    @RequestMapping("/selectPatentNameById")
    public String[] selectPatentNameById(@RequestParam String patentId){
        return patentServer.selectPatentNameById(patentId);
    }

}
